/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hcsc.datapower.CMDB.daoImpl;

import com.hcsc.datapower.CMDB.dao.AbstractDao;
import com.hcsc.datapower.CMDB.dao.ServiceDao;
import com.hcsc.datapower.CMDB.integration.ServiceInformation;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.RowMapper;

/**
 *
 * @author I307211
 */
public class ServiceDaoImpl extends AbstractDao implements ServiceDao{

    
    @Override
    public List<ServiceInformation> getServices(String env, String domain) {
        
        String sql = "SELECT * FROM Services " +
       "WHERE ((Services.Platform = ? )) AND ((Services.Domain_Name = ?)) " +
       "ORDER by Services.Service";
        List<ServiceInformation> tmp = this.jdbcTemplate.query(sql, new Object[] {env, domain}, new ServiceInfoMapper());
        
        if(tmp!=null)
            return tmp;
        return null;
    }


    @Override
    public List<String> getServiceNames(String env, String domain) {

        return null;
    }

    @Override
    public ServiceInformation getServiceByName(String serviceName) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int addService(ServiceInformation service) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int removeService(ServiceInformation service) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int updateService(ServiceInformation service) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    private static final class ServiceInfoMapper implements RowMapper {

    public Object mapRow(ResultSet rs, int i) throws SQLException {
                ServiceInformation t = new ServiceInformation();
                t.setPlatform(rs.getString("Platform"));
                t.setDomain_name(rs.getString("Domain_name"));
                t.setService(rs.getString("Service"));
                t.setHwDevice(rs.getString("HwDevice"));
                t.setActive(rs.getInt("Active"));
                t.setProtocol(rs.getString("Protocol"));
                t.setPort(rs.getString("Port"));
                t.setMQ_FSH_QM(rs.getString("MQ_FSH_QM"));
                t.setMQ_FSH_Get_QName(rs.getString("MQ_FSH_Get_QName"));
                t.setDirection(rs.getString("Direction"));
                t.setTranType(rs.getString("TranType"));
                t.setDP_URI(rs.getString("DP_URI"));
                t.setBackend_URL(rs.getString("Backend_URL"));
                t.setESBUI_Value(rs.getString("ESBUI_Value"));
                t.setDeploy_Pol_Loc(rs.getString("Deploy_Pol_Loc"));
                t.setTest_Case_Loc(rs.getString("Test_Case_Loc"));
                t.setDeveloper(rs.getString("Developer"));
                t.setBusiness_Owner(rs.getString("Business_Owner"));
                t.setConfig_Notes(rs.getString("Config_Notes"));
                t.setComments(rs.getString("Comments"));
                t.setWhoUpdated(rs.getString("WhoUpdated"));
                t.setTimeUpdated(rs.getString("TimeUpdated"));
                return t;
        }
    }
}
